<template>
	<uv-popup ref="popup" mode="right">
		<view class="content">
			<view class="item" v-for="(item,index) in list" :key="index" style="width: 320px;height: 125px;background: rgba(0, 0, 0, 0.5);margin: 10px auto;border-radius: 10px;">
				<view class="info uv-flex-row" style="align-items: center;">
					<uv-avatar :src="`/static/images/character/${item.avatar}-small.png`" size="40px" mode="aspectFill"></uv-avatar>
					<view><uv-text :text="item.nickname" color="#fff" margin="0 0 0 10px"></uv-text></view>
				</view>
				<view class="btns uv-flex-row">
					<uv-button text="拒绝" type="error" @click="refuse(item)"></uv-button>
					<uv-button text="同意" type="success" @click="agree(item)"></uv-button>
				</view>
			</view>
			<uv-empty text="暂无数据~" v-if="!list.length"></uv-empty>
		</view>
	</uv-popup>
</template>
<script setup>
	import { ref } from 'vue';
	const db = uniCloud.database();
	import { groupApplyChange } from '@/common/api/group.js';
	const popup = ref(null);
	const emits = defineEmits(['reload']);
	const { list = [] } = defineProps({
		list: Array
	})
	async function refuse(item) {
		const characterId = getApp().globalData.dzcharacter?.character?.characterId;
		await groupApplyChange({
			action: 'reply',
			characterId,
			applyCharacterId: item.characterId,
			groupCode: item.groupCode,
			applyStatus: 'REFUSE'
		})
		emits('reload');
	}
	async function agree(item) {
		const characterId = getApp().globalData.dzcharacter?.character?.characterId;
		await groupApplyChange({
			action: 'reply',
			characterId,
			applyCharacterId: item.characterId,
			groupCode: item.groupCode,
			applyStatus: 'AGREE'
		})
		emits('reload');
	}

	function open() {
		popup.value.open();
	}
	defineExpose({
		open
	})
</script>
<style scoped lang="scss">
	.content {
		width: 400px;
	}
</style>